package com.cn.view;

import com.cn.bean.Department;
import com.cn.bean.Worker;
import com.cn.dao.DepartmentDao;
import com.cn.dao.WorkerDao;
import com.cn.util.StringUtils;

import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Vector;

public class WorkerManageFrame extends JInternalFrame {
    private JTable workerTable;
    private JTextField searchNameTextField;
    private JTextField searchSnTextField;
    private JComboBox searchDepartmentComboBox;
    private JRadioButton maleRadioButton;
    private JRadioButton femaleRadioButton;
    private JTextArea addressTextArea;
    private JComboBox modifyDepartmentComboBox;
    private JTextField idTextField;
    private JTextField nameTextField;
    private final ButtonGroup buttonGroup = new ButtonGroup();
    private JTextField deptTextField;
    private JTextField snTextField;

    /**
     * Create the frame.
     */
    public WorkerManageFrame(){
        setClosable(true);
        setIconifiable(true);
        setTitle("员工信息管理主界面");
        setBounds(100, 100, 677, 487);
        JScrollPane scrollPane = new JScrollPane();
        JPanel panel = new JPanel();
        panel.setBorder(new TitledBorder(null, "查询", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        JPanel panel_1 = new JPanel();
        panel_1.setBorder(new TitledBorder(null, "操作", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        GroupLayout groupLayout = new GroupLayout(getContentPane());
        GroupLayout.ParallelGroup createParallelGroup1 = groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
        GroupLayout.SequentialGroup createSequentialGroup1 = groupLayout.createSequentialGroup();
        createSequentialGroup1.addContainerGap();
        GroupLayout.ParallelGroup createParallelGroup2 = groupLayout.createParallelGroup(GroupLayout.Alignment.TRAILING);
        createParallelGroup2.addComponent(panel_1, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
        GroupLayout.ParallelGroup createParallelGroup3 = groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false);
        createParallelGroup3.addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
        createParallelGroup3.addComponent(scrollPane);
        createParallelGroup2.addGroup(GroupLayout.Alignment.LEADING,createParallelGroup3);
        createSequentialGroup1.addGroup(createParallelGroup2);
        createSequentialGroup1.addContainerGap(66, Short.MAX_VALUE);
        createParallelGroup1.addGroup(createSequentialGroup1);
        groupLayout.setHorizontalGroup(createParallelGroup1);
        GroupLayout.ParallelGroup createParallelGroup4 = groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
        GroupLayout.SequentialGroup createSequentialGroup3 = groupLayout.createSequentialGroup();
        createSequentialGroup3.addGap(28);
        createSequentialGroup3.addComponent(panel, GroupLayout.PREFERRED_SIZE, 65, GroupLayout.PREFERRED_SIZE);
        createSequentialGroup3.addGap(18);
        createSequentialGroup3.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE);
        createSequentialGroup3.addGap(18);
        createSequentialGroup3.addComponent(panel_1, GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE);
        createSequentialGroup3.addContainerGap();
        createParallelGroup4.addGroup(createSequentialGroup3);
        groupLayout.setVerticalGroup(createParallelGroup4);
        JLabel lblNewLabel = new JLabel("编号：");
        idTextField = new JTextField();
        idTextField.setEditable(false);
        idTextField.setColumns(10);
        JLabel lblNewLabel_1 = new JLabel("员工姓名");
        nameTextField = new JTextField();
        nameTextField.setColumns(10);
        JLabel label_3 = new JLabel("员工性别");
        maleRadioButton = new JRadioButton("男");
        buttonGroup.add(maleRadioButton);
        maleRadioButton.setSelected(true);
        femaleRadioButton = new JRadioButton("女");
        buttonGroup.add(femaleRadioButton);
        JLabel label_4 = new JLabel("所在部门岗位");
        deptTextField = new JTextField();
        deptTextField.setColumns(10);
        JLabel lblNewLabel_2 = new JLabel("员工工号");
        snTextField = new JTextField();
        snTextField.setColumns(10);
        JLabel label_5 = new JLabel("所属部门");
        modifyDepartmentComboBox = new JComboBox();
        JLabel label_6 = new JLabel("家庭住址");
        addressTextArea = new JTextArea();
        // 点击"修改"按钮执行update()方法
        JButton updateButton = new JButton("修改");
        updateButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                update();
            }
        });
        updateButton.setIcon(new ImageIcon(WorkerManageFrame.class.getResource("/images/modify.png")));

        // 点击"修改"按钮执行update()方法
        JButton deleteButton = new JButton("删除");
        deleteButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                delete();
            }
        });
        deleteButton.setIcon(new ImageIcon(WorkerManageFrame.class.getResource("/images/delete.png")));
        GroupLayout gl_panel_1 = new GroupLayout(panel_1);
        GroupLayout.ParallelGroup group1 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.LEADING);
        GroupLayout.SequentialGroup sGroup1 = gl_panel_1.createSequentialGroup();
        sGroup1.addGap(19);
        GroupLayout.ParallelGroup group2 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.LEADING);
        GroupLayout.SequentialGroup sGroup2 = gl_panel_1.createSequentialGroup();
        sGroup2.addComponent(updateButton);
        sGroup2.addGap(18);
        sGroup2.addComponent(deleteButton);
        sGroup2.addGap(386);
        group2.addGroup(sGroup2);
        GroupLayout.SequentialGroup sGroup3 = gl_panel_1.createSequentialGroup();
        GroupLayout.ParallelGroup group3 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.LEADING);
        GroupLayout.SequentialGroup sGroup4 = gl_panel_1.createSequentialGroup();
        sGroup4.addComponent(label_6);
        sGroup4.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
        sGroup4.addComponent(addressTextArea);
        group3.addGroup(sGroup4);
        GroupLayout.SequentialGroup sGroup5 = gl_panel_1.createSequentialGroup();
        GroupLayout.ParallelGroup group4 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.LEADING, false);
        GroupLayout.SequentialGroup sGroup6 = gl_panel_1.createSequentialGroup();
        sGroup6.addComponent(label_4);
        sGroup6.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
        sGroup6.addComponent(deptTextField);
        group4.addGroup(sGroup6);
        GroupLayout.SequentialGroup sGroup7 = gl_panel_1.createSequentialGroup();
        sGroup7.addComponent(lblNewLabel);
        sGroup7.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
        sGroup7.addComponent(idTextField, GroupLayout.PREFERRED_SIZE, 87, GroupLayout.PREFERRED_SIZE);
        group4.addGroup(sGroup7);
        sGroup5.addGroup(group4);
        sGroup5.addGap(26);
        GroupLayout.ParallelGroup group5 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.LEADING, false);
        GroupLayout.SequentialGroup sGroup8 = gl_panel_1.createSequentialGroup();
        sGroup8.addComponent(lblNewLabel_1);
        sGroup8.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
        sGroup8.addComponent(nameTextField, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE);
        group5.addGroup(sGroup8);
        GroupLayout.SequentialGroup sGroup9 = gl_panel_1.createSequentialGroup();
        sGroup9.addComponent(lblNewLabel_2);
        sGroup9.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
        sGroup9.addComponent(snTextField);
        group5.addGroup(sGroup9);
        sGroup5.addGroup(group5);
        sGroup5.addGap(26);
        GroupLayout.ParallelGroup group6 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.LEADING, false);
        GroupLayout.SequentialGroup sGroup10 = gl_panel_1.createSequentialGroup();
        sGroup10.addComponent(label_3);
        sGroup10.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
        sGroup10.addComponent(maleRadioButton);
        sGroup10.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
        sGroup10.addComponent(femaleRadioButton);
        group6.addGroup(sGroup10);
        GroupLayout.SequentialGroup sGroup11 = gl_panel_1.createSequentialGroup();
        sGroup11.addComponent(label_5);
        sGroup11.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
        sGroup11.addComponent(modifyDepartmentComboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
        group6.addGroup(sGroup11);
        sGroup5.addGroup(group6);
        group3.addGroup(sGroup5);
        sGroup3.addGroup(group3);
        sGroup3.addContainerGap(86, Short.MAX_VALUE);
        group2.addGroup(sGroup3);
        sGroup1.addGroup(group2);
        group1.addGroup(sGroup1);
        gl_panel_1.setHorizontalGroup(group1);
        GroupLayout.ParallelGroup pGroup1 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.LEADING);
        GroupLayout.SequentialGroup seGroup1 = gl_panel_1.createSequentialGroup();
        seGroup1.addGap(21);
        GroupLayout.ParallelGroup pGroup2 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.BASELINE);
        pGroup2.addComponent(lblNewLabel);
        pGroup2.addComponent(idTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
        pGroup2.addComponent(lblNewLabel_1);
        pGroup2.addComponent(nameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
        pGroup2.addComponent(label_3);
        pGroup2.addComponent(maleRadioButton);
        pGroup2.addComponent(femaleRadioButton);
        seGroup1.addGroup(pGroup2);
        seGroup1.addGap(18);
        GroupLayout.ParallelGroup pGroup3 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.BASELINE);
        pGroup3.addComponent(label_4);
        pGroup3.addComponent(deptTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
        pGroup3.addComponent(lblNewLabel_2);
        pGroup3.addComponent(snTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
        pGroup3.addComponent(label_5);
        pGroup3.addComponent(modifyDepartmentComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
        seGroup1.addGroup(pGroup3);
        seGroup1.addGap(18);
        GroupLayout.ParallelGroup pGroup4 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.LEADING);
        pGroup4.addComponent(label_6);
        pGroup4.addComponent(addressTextArea, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE);
        seGroup1.addGroup(pGroup4);
        seGroup1.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE);
        GroupLayout.ParallelGroup pGroup5 = gl_panel_1.createParallelGroup(GroupLayout.Alignment.BASELINE);
        pGroup5.addComponent(updateButton);
        pGroup5.addComponent(deleteButton);
        seGroup1.addGroup(pGroup5);
        pGroup1.addGroup(seGroup1);
        gl_panel_1.setVerticalGroup(pGroup1);
        panel_1.setLayout(gl_panel_1);
        // 以下员工姓名、员工编号、所属部门用于查询
        JLabel label = new JLabel("员工姓名");
        searchNameTextField = new JTextField();
        searchNameTextField.setColumns(10);
        JLabel label_1 = new JLabel("员工工号");
        searchSnTextField = new JTextField();
        searchSnTextField.setColumns(10);
        JLabel label_2 = new JLabel("所属部门");
        searchDepartmentComboBox = new JComboBox();
        // 点击"查询"按钮执行search()方法
        JButton searchButton = new JButton("查询");
        searchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                search();
            }
        });
        searchButton.setIcon(new ImageIcon(WorkerManageFrame.class.getResource("/images/search.png")));
        GroupLayout gl_panel = new GroupLayout(panel);
        GroupLayout.ParallelGroup parallelGroup1 = gl_panel.createParallelGroup(GroupLayout.Alignment.LEADING);
        GroupLayout.SequentialGroup sequentialGroup1 = gl_panel.createSequentialGroup();
        sequentialGroup1.addGap(19);
        sequentialGroup1.addComponent(label);
        sequentialGroup1.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
        sequentialGroup1.addComponent(searchNameTextField, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE);
        sequentialGroup1.addGap(18);
        sequentialGroup1.addComponent(label_1);
        sequentialGroup1.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
        sequentialGroup1.addComponent(searchSnTextField, GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE);
        sequentialGroup1.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
        sequentialGroup1.addComponent(label_2);
        sequentialGroup1.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED);
        sequentialGroup1.addComponent(searchDepartmentComboBox, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE);
        sequentialGroup1.addGap(18);
        sequentialGroup1.addComponent(searchButton);
        sequentialGroup1.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
        parallelGroup1.addGroup(sequentialGroup1);
        gl_panel.setHorizontalGroup(parallelGroup1);
        GroupLayout.ParallelGroup parallelGroup2 = gl_panel.createParallelGroup(GroupLayout.Alignment.TRAILING);
        GroupLayout.SequentialGroup sequentialGroup2 = gl_panel.createSequentialGroup();
        sequentialGroup2.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
        GroupLayout.ParallelGroup parallelGroup3 = gl_panel.createParallelGroup(GroupLayout.Alignment.BASELINE);
        parallelGroup3.addComponent(label);
        parallelGroup3.addComponent(searchNameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
        parallelGroup3.addComponent(label_1);
        parallelGroup3.addComponent(searchSnTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
        parallelGroup3.addComponent(label_2);
        parallelGroup3.addComponent(searchDepartmentComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE);
        parallelGroup3.addComponent(searchButton);
        sequentialGroup2.addGroup(parallelGroup3);
        sequentialGroup2.addGap(16);
        parallelGroup2.addGroup(sequentialGroup2);
        gl_panel.setVerticalGroup(parallelGroup2);
        panel.setLayout(gl_panel);
        // 点击员工列表中的某个员工执行click()方法
        workerTable = new JTable();
        workerTable.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent met) {
                click();
            }
        });
        scrollPane.setViewportView(workerTable);
        workerTable.setModel(new DefaultTableModel(
                new Object[][] {},
                new String[] {"编号", "员工姓名", "员工工号", "员工性别", "所在部门岗位", "家庭住址", "所属部门"}
        ) {
            boolean[] columnEditables = new boolean[] {false, false, false, false, false, false, false};
            public boolean isCellEditable(int row, int column) {
                return columnEditables[column];
            }
        });
        workerTable.getColumnModel().getColumn(5).setPreferredWidth(119);
        getContentPane().setLayout(groupLayout);
        addressTextArea.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false));
        // 初始化查询时用到的部门下拉列表
        this.initSchoolClassComboBoxForSearch();
        // 初始化修改时用到的部门下拉列表
        this.initSchoolClassComboForModify();
        // 初始化员工表格
        this.initWorkerTable(null);
    }

    /**
     * core code
     * 初始化查询员工时所用的所属部门下拉列表
     */
    private void initSchoolClassComboBoxForSearch() {
        Department department = new Department();
        department.setDeptName("请选择...");
        department.setDeptId(-1);
        this.searchDepartmentComboBox.addItem(department);
        // 利用DepartmentDao查询所有部门
        DepartmentDao departmentDao=new DepartmentDao();
        ArrayList<Department> list = departmentDao.query(null);
        for (int i = 0; i < list.size(); i++) {
            Department dept = list.get(i);
            this.searchDepartmentComboBox.addItem(dept);
        }
    }

    /**
     * core code
     * 初始化更新员工时所用的所属部门下拉列表
     */
    private void initSchoolClassComboForModify() {
        // 利用DepartmentDao查询所有部门
        DepartmentDao departmentDao=new DepartmentDao();
        ArrayList<Department> list = departmentDao.query(null);
        for (int i = 0; i < list.size(); i++) {
            Department dept = list.get(i);
            this.modifyDepartmentComboBox.addItem(dept);
        }
    }

    /**
     * core code
     * 初始化员工表格
     */
    private void initWorkerTable(Worker worker){
        DefaultTableModel tableModel=(DefaultTableModel) workerTable.getModel();
        tableModel.setRowCount(0);
        // 利用WorkerDao查询员工
        WorkerDao workerDao=new WorkerDao();
        ArrayList<Worker> list=workerDao.query(worker);
        for(int i=0;i<list.size();i++){
            Worker wk = list.get(i);
            Vector v=new Vector();
            v.add(wk.getWorkerID());
            v.add(wk.getWorkerName());
            v.add(wk.getWorkerNumber());
            v.add(wk.getWorkerSex());
            v.add(wk.getDept());
            v.add(wk.getWorkerAddress());
            v.add(wk.getDepartmentName());
            tableModel.addRow(v);
            System.out.println(wk.getWorkerID()+" "+wk.getWorkerName()+" "+wk.getWorkerNumber()+" "+wk.getWorkerSex()+" "+wk.getDept()+" "+wk.getWorkerAddress()+" "+wk.getDepartmentName());
        }
    }

    /**
     * core code
     * 查询员工
     */
    private void search() {
        // 获取查询条件并封装为Worker对象
        String name=this.searchNameTextField.getText();
        String sn=this.searchSnTextField.getText();
        Department department=(Department) this.searchDepartmentComboBox.getSelectedItem();
        int id=department.getDeptId();
        Worker worker=new Worker(name,sn,id);
        // 初始化员工表格
        this.initWorkerTable(worker);
    }

    /**
     * core code
     * 处理员工表格中某行点击事件
     */
    private void click() {
        int row=this.workerTable.getSelectedRow();
        String id = workerTable.getValueAt(row, 0)+"";
        this.idTextField.setText(id);
        String name = (String)workerTable.getValueAt(row, 1);
        this.nameTextField.setText(name);
        String sn = (String)workerTable.getValueAt(row, 2);
        this.snTextField.setText(sn);
        String sex=(String)workerTable.getValueAt(row, 3);
        if("男".equals(sex)){
            this.maleRadioButton.setSelected(true);
        }else if("女".equals(sex)){
            this.femaleRadioButton.setSelected(true);
        }
        String dept = workerTable.getValueAt(row, 4)+"";
        this.deptTextField.setText(dept);
        String address = (String)workerTable.getValueAt(row, 5);
        this.addressTextArea.setText(address);
        String className=(String)this.workerTable.getValueAt(row, 6);
        int itemCount=this.modifyDepartmentComboBox.getItemCount();
        for(int i=0;i<itemCount;i++){
            Department item=(Department) this.modifyDepartmentComboBox.getItemAt(i);
            if(item.getDeptName().equals(className)){
                this.modifyDepartmentComboBox.setSelectedIndex(i);
                break;
            }
        }
    }

    /**
     * core code
     * 删除员工
     */
    private void delete() {
        String id = idTextField.getText();
        if (StringUtils.isEmpty(id)) {
            JOptionPane.showMessageDialog(null, "请选择要删除的记录");
            return;
        }
        int select = JOptionPane.showConfirmDialog(null, "确定要删除该记录吗？");
        // 确定删除
        if (select == JOptionPane.YES_OPTION) {
            // 利用WorkerDao删除员工
            WorkerDao workerDao=new WorkerDao();
            int result = workerDao.delete(Integer.parseInt(id));
            if (result == 1) {
                JOptionPane.showMessageDialog(null, "删除成功");
                this.reset();
                this.initWorkerTable(null);
            } else {
                JOptionPane.showMessageDialog(null, "删除失败");
            }
        }
    }

    /**
     * core code
     * 修改员工
     */
    private void update() {
        String id=this.idTextField.getText();
        if(StringUtils.isEmpty(id)){
            JOptionPane.showMessageDialog(null, "请选择要修改的记录");
            return;
        }
        String name=this.nameTextField.getText();
        String sn=this.snTextField.getText();
        String dept=this.deptTextField.getText();
        String address=this.addressTextArea.getText();

        if(StringUtils.isEmpty(name)){
            JOptionPane.showMessageDialog(null, "员工姓名不能为空！");
            return;
        }

        if(StringUtils.isEmpty(sn)){
            JOptionPane.showMessageDialog(null, "员工工号不能为空！");
            return;
        }

        if(StringUtils.isEmpty(dept)){
            JOptionPane.showMessageDialog(null, "员工所在部门岗位不能为空！");
            return;
        }

        String sex="";
        if(maleRadioButton.isSelected()){
            sex="男";
        }else if(femaleRadioButton.isSelected()){
            sex="女";
        }
        Department department=(Department) modifyDepartmentComboBox.getSelectedItem();
        int scId=department.getDeptId();

        // 利用StudentDao更新员工
        WorkerDao workerDao=new WorkerDao();
        Worker worker=new Worker(Integer.parseInt(id),  name, sn, sex, dept,  scId,  address);
        int result=workerDao.update(worker);
        if(result==1){
            JOptionPane.showMessageDialog(null, "员工信息修改成功！");
            reset();
            this.initWorkerTable(null);
        }else{
            JOptionPane.showMessageDialog(null, "员工信息修改失败！");
        }

    }

    /**
     * core code
     * 重置
     */
    private void reset(){
        this.idTextField.setText("");
        this.nameTextField.setText("");
        this.snTextField.setText("");
        this.deptTextField.setText("");
        this.maleRadioButton.setSelected(true);
        this.addressTextArea.setText("");
        if(this.modifyDepartmentComboBox.getItemCount()>0){
            this.modifyDepartmentComboBox.setSelectedIndex(0);
        }
    }
}
